using System;
using System.Collections;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using System.Runtime.CompilerServices;
using DevExpress.XtraGrid.Views.Base; //JMR -- added, might be used for RowHandle



namespace ePlanSysOman
{
  public partial class frmStepWires
  {

      string REFALL = "";
      string REFNEW = "";
      string REFOLD = "";
    private void  // ERROR: Handles clauses are not supported in C#
btnAddParts_Click(System.Object sender, System.EventArgs e)
    {

        Module1.newModule.ISRUNN = true;


        Module1.newModule.electrical = true;
        if (Module1.newModule.backshop)
        {
        this.grdBackshop.BringToFront();
        Module1.newModule.PartsStep = Module1.newModule.GetSelectedValues(this.GridView2);
      } else {
        this.gridStepWires.BringToFront();
        if ((this.XtraTabControl1.SelectedTabPageIndex == 0)) {
            if (Module1.newModule.opsisopened)
            {
            this.GridView1.SelectAll();
            Module1.newModule.PartsStep = Module1.newModule.GetSelectedValues(this.GridView1);
          } else {
              Module1.newModule.PartsStep = Module1.newModule.GetSelectedValues(this.GridView1);
          }
        } else if ((this.XtraTabControl1.SelectedTabPageIndex == 3)) {
            Module1.newModule.PartsStep = Module1.newModule.GetSelectedValues(this.GridView3);
          DataSet aset = new DataSet();
          clsData data = new clsData();
          Module1.newModule.PLUG = Conversions.ToString(this.GridView3.GetRowCellValue(this.GridView3.GetSelectedRows()[0], "PTNUMBER"));//JMR -- Converted to string
          if ((data.getData(string.Concat(new string[] {
            "SELECT * FROM TBLREFDESCOMP WHERE PARTNUMBER ='",
            Module1.newModule.PLUG,
            "' AND  LOCATION ='",
            Module1.newModule.CountRefDes,
            "' AND REFCOMPPLID ='",
            Module1.newModule.PlanNumber,
            "'"
          })).Tables[0].Rows.Count == 0)) {
            string sQL = "INSERT INTO tblREFDESCOMP";
            sQL = (sQL + "(PARTNUMBER,DESCRIPTION,QTY,REFACTION,LOCATION,HREFCOMPID,REFCOMPPLID,REFDESCOMID) VALUES");

            //JMR 0x5f5e0ff was &H5F5E0FF in the .vb file
              sQL = string.Concat(new string[] {
              sQL,
              "('",
              Module1.newModule.PLUG,
              "','PLUG','AR','ADD','",
              Module1.newModule.CountRefDes,
              "','",
              Module1.newModule.HARNESSID,
              "','",
              Module1.newModule.PlanNumber,
              "',",
              Conversions.ToString(0x5f5e0ff),
              ")"
            });
            data.ExecuteSQL(sQL);
          }
        }
        Module1.newModule.STEPWIRESON = true;
        this.CheckBox1.CheckState = CheckState.Unchecked;
      }
      this.Dispose();
      Module1.newModule.electrical = false;

      if (Module1.newModule.opsisopened)
      {
          Module1.newModule.opsisopened = false;
        this.Close();
      }
      //'Dim ANS As DialogResult
      //'If stpParts = True Then
      //'    electrical = True
      //'    If backshop = True Then
      //'        grdBackshop.BringToFront()
      //'        PartsStep = GetSelectedValues(GridView2)
      //'    Else
      //'        gridStepWires.BringToFront()
      //'        PartsStep = GetSelectedValues(GridView1)
      //'    End If
      //'    ANS = XtraMessageBox.Show("Add more Parts", "Adding Parts", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
      //'    If ANS = Windows.Forms.DialogResult.No Then
      //'        Me.Dispose()
      //'    End If
      //'    electrical = False
      //'End If
    }

    private void  // ERROR: Handles clauses are not supported in C#
btnExit_Click(System.Object sender, System.EventArgs e)
    {
        Module1.newModule.PartsStep = null;
        Module1.newModule.HASSHIELDS = false;
      this.Dispose();
    }

    private void  // ERROR: Handles clauses are not supported in C#
CardView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)//JMR -- changing variable type of e to DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs fixes the issue
    {                           
      //  //JMR -- look at -- issue has to deal with declaration type of 'e'
      //if (this.CardView1.GetRowCellValue(e.RowHandle, "8")!= "0") {
      //    //if (this.CardView1.GetRowCellValue(e.ListSourceRowIndex, "8") != "0") {
      //  this.CardView1.Columns["8"].Visible = false; 
      //}
      //if (this.CardView1.GetRowCellValue(e.RowHandle, "12") != "0")
      ////if (this.CardView1.GetRowCellValue(e.ListSourceRowIndex, "12") != "0") {
      //{
      //  this.CardView1.Columns["12"].Visible = false;
      //}
      //if (this.CardView1.GetRowCellValue(e.RowHandle, "16") != "0") {
      //    //if (this.CardView1.GetRowCellValue(e.ListSourceRowIndex, "16") != "0") {
      //  this.CardView1.Columns["16"].Visible = false;
      //}
      //if (this.CardView1.GetRowCellValue(e.RowHandle, "20") != "0") {
      //    //if (this.CardView1.GetRowCellValue(e.ListSourceRowIndex, "20") != "0") {
      //  this.CardView1.Columns["20"].Visible = false;
      //}
      //if (this.CardView1.GetRowCellValue(e.RowHandle, "22") != "0") {
      //    //if (this.CardView1.GetRowCellValue(e.ListSourceRowIndex, "22") != "0") {
      //  this.CardView1.Columns["22"].Visible = false;
      //}
      //if (this.CardView1.GetRowCellValue(e.RowHandle, "SOLDER") != "0") {
      //    //if (this.CardView1.GetRowCellValue(e.ListSourceRowIndex, "SOLDER") != "0") {
      //  this.CardView1.Columns["SOLDER"].Visible = false;
      //}
    }

    private void  // ERROR: Handles clauses are not supported in C#
frmStepWires_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
    {
        if (Module1.newModule.ISRUNN)
        {
            Module1.newModule.ISRUNN = false;
      } else {
          Module1.newModule.PartsStep = null;
          Module1.newModule.HASSHIELDS = false;
        this.Dispose();
        Module1.newModule.ISRUNN2 = false;


      }
    }

    private void  // ERROR: Handles clauses are not supported in C#
frmStepWires_Load(object sender, System.EventArgs e)
    {
      this.CheckBox1.CheckState = CheckState.Checked;
      DataSet aset = new DataSet();
      clsData data = new clsData();
      Module1.newModule.PlanNumber = Module1.newModule.plnumber;
      REFALL = Module1.newModule.CountRefDes;
      aset = data.getData("SELECT * FROM PTP WHERE 1=2");
      if ((aset.Tables[0].Rows.Count == 0)) {
        // Me.tabShields.PageVisible = False
      }
      //  Me.grdShields.DataSource =aset.Tables.Item(0)
      DataSet set2 = new DataSet();
      clsData data2 = new clsData();
      if (Module1.newModule.CountRefDes.Contains("("))
      {
        REFNEW = Module1.newModule.CountRefDes.Substring(0, Module1.newModule.CountRefDes.IndexOf("(")).Trim();
        this.REFOLD = Module1.newModule.CountRefDes.Substring((Module1.newModule.CountRefDes.IndexOf("(") + 4)).Trim();
        this.REFOLD = this.REFOLD.Substring(0, (this.REFOLD.Length - 1));
        set2 = data2.getData(string.Concat(new string[] {
          "select * from PTP2 where WIRE_END_REF ='",
          this.REFNEW,
          "' AND PART_NUMBER ='",
          Module1.newModule.newharn,
          "' or WIRE_END_REF ='",
          this.REFOLD,
          "' AND PART_NUMBER ='",
          Module1.newModule.oldharn,
          "'"
        }));
      } else {
          this.REFOLD = Module1.newModule.CountRefDes;
          this.REFNEW = Module1.newModule.CountRefDes;
        set2 = data2.getData(string.Concat(new string[] {
          "select * from PTP2 where WIRE_END_REF ='",
          Module1.newModule.CountRefDes,
          "' AND PART_NUMBER ='",
          Module1.newModule.newharn,
          "' or WIRE_END_REF ='",
          Module1.newModule.CountRefDes,
          "' AND PART_NUMBER ='",
          Module1.newModule.oldharn,
          "'"
        }));
      }
      this.grdWires.DataSource = set2.Tables[0];
      this.grdWires.Refresh();
      if (Module1.newModule.opsisopened)
      {
        this.Opacity = (0);
        this.btnAddParts.PerformClick();
      } else {
        this.Opacity = (100);
      }
    }

    private void  // ERROR: Handles clauses are not supported in C#
SimpleButton1_Click(System.Object sender, System.EventArgs e)
    {

      string str;
      string con = "";

      DataSet aset = new DataSet();
      clsData data = new clsData();
      clsData data2 = new clsData();
      aset = data2.getData(string.Concat(new string[] {
        "SELECT REFDESID  FROM TBLREFDES WHERE REFDES = '",
        Module1.newModule.refdecount,
        "' AND REFPLANID ='",
        Module1.newModule.PlanNumber,
        "'"
      }));
      if ((aset.Tables[0].Rows.Count == 0)) {
        data2.ExecuteSQL(string.Concat(new string[] {
          "INSERT INTO TBLREFDES (REFDES,REPORTNOTE,OPN,HARNESS,REFPLANID,REFWT,REFPREVIEW) VALUES ('",
          Module1.newModule.CountRefDes,
          "','',2,'",
          Module1.newModule.HARNESSID,
          "','",
          Module1.newModule.PlanNumber,
          "','Rework wires at  ",
          Module1.newModule.RefDes,
          " as follows and per 16PR145','')"
        }));
        str = string.Concat(new string[] {
          "SELECT REFDESID AS REFDESID FROM TBLREFDES WHERE REFDES = '",
          Module1.newModule.CountRefDes,
          "' AND REFPLANID ='",
          Module1.newModule.PlanNumber,
          "'"
        });
        Module1.newModule.RefDesId = Conversions.ToInteger(data2.getData(str).Tables[0].Rows[0]["REFDESID"]);
      } else {
          Module1.newModule.RefDesId = Conversions.ToInteger(aset.Tables[0].Rows[0]["REFDESID"]);
      }
      if (Module1.newModule.refdecount.Contains("NEAR"))
      {
        con = Module1.newModule.refdecount.Substring(0, Module1.newModule.refdecount.IndexOf("(")).Trim();//JMR added Module1.newModule onto the second refdecount, while the first one I only replaced Module1 with Module1.newModule
      } else {
          con = Module1.newModule.refdecount;

      }

      data.ExecuteSQL(string.Concat(new string[] {
        "update TBLREFDES set baseref ='" + con + "',OPN = '2' where REFDESID = ",
        Conversions.ToString(Module1.newModule.RefDesId),
        " AND RefPlanId ='",
        Module1.newModule.PlanNumber,
        "'"
      }));
      data.ExecuteSQL(string.Concat(new string[] {
        "DELETE * FROM TBLBACKSHOPWIRES WHERE bacRefdes1 ='",
        Module1.newModule.refdecount,
        "' AND bacPlId ='",
        Module1.newModule.PlanNumber,
        "'"
      }));
      data.ExecuteSQL(string.Concat(new string[] {
        "DELETE * FROM TBLBACKSHOPWIRES WHERE bacRefdes2 ='",
        Module1.newModule.refdecount,
        "' AND bacPlId ='",
        Module1.newModule.PlanNumber,
        "'"
      }));
      data.ExecuteSQL(string.Concat(new string[] {
        "DELETE * FROM TBLWIRESREVISE WHERE WREFDESID =",
        Conversions.ToString(Module1.newModule.RefDesId),
        " AND WIRESPLID ='",
        Module1.newModule.PlanNumber,
        "'"
      }));
      data.ExecuteSQL(string.Concat(new string[] {
        "DELETE * FROM TBLWIRES WHERE WREFDESID =",
        Conversions.ToString(Module1.newModule.RefDesId),
        " AND WIRESPLID ='",
        Module1.newModule.PlanNumber,
        "'"
      }));
      data.ExecuteSQL(string.Concat(new string[] {
        "DELETE * FROM TBLWIRESadd WHERE WREFDESID =",
        Conversions.ToString(Module1.newModule.RefDesId),
        " AND WIRESPLID ='",
        Module1.newModule.PlanNumber,
        "'"
      }));
      data.ExecuteSQL(string.Concat(new string[] {
        "DELETE * FROM TBLWIRES WHERE WREFDESID =",
        Conversions.ToString(Module1.newModule.RefDesId),
        " AND WIRESPLID ='",
        Module1.newModule.PlanNumber,
        "'"
      }));
      data.ExecuteSQL(string.Concat(new string[] {
        "DELETE * FROM TBLWIRESREMOVE WHERE WREFDESID =",
        Conversions.ToString(Module1.newModule.RefDesId),
        " AND WIRESPLID ='",
        Module1.newModule.PlanNumber,
        "'"
      }));
      data.ExecuteSQL(string.Concat(new string[] {
        "DELETE * FROM TBLWIRESADD WHERE WREFDESID =",
        Conversions.ToString(Module1.newModule.RefDesId),
        " AND WIRESPLID ='",
        Module1.newModule.PlanNumber,
        "'"
      }));
      data.ExecuteSQL(string.Concat(new string[] {
        "DELETE * FROM TBLWIRESBACKSHELL WHERE WREFDESID =",
        Conversions.ToString(Module1.newModule.RefDesId),
        " AND WIRESPLID ='",
        Module1.newModule.PlanNumber,
        "'"
      }));
      data.ExecuteSQL(string.Concat(new string[] {
        "DELETE * FROM TBLWIRESREVISE WHERE WREFDESID =",
        Conversions.ToString(Module1.newModule.RefDesId),
        " AND WIRESPLID ='",
        Module1.newModule.PlanNumber,
        "'"
      }));
      data.ExecuteSQL(string.Concat(new string[] {
        "DELETE * FROM tblmisc where miscrefdesid = ",
        Conversions.ToString(Module1.newModule.RefDesId),
        " AND MISCPLANID ='",
        Module1.newModule.PlanNumber,
        "'"
      }));
      aset = data2.getData(string.Concat(new string[] {
        " SELECT * FROM PTP TBL1 WHERE  PART_NUMBER = '",
        Module1.newModule.oldharn,
        "' AND TBL1.WIRE_END_REF ='",
        Module1.newModule.CountRefDes,
        "' AND  WIRE_NUMBER NOT IN( SELECT WIRE_NUMBER FROM PTP TBL2 WHERE  ((TBL1.WIRE_END_PIN = TBL2.WIRE_END_PIN)OR(TBL1.WIRE_END_PIN IS NULL AND TBL2.WIRE_END_PIN = '-' ))  AND TBL1.WIRE_END_REF = TBL2.WIRE_END_REF AND ((TBL1.WIRE_END_PN = TBL2.WIRE_END_PN)OR (TBL1.WIRE_END_PN IS NULL AND TBL2.WIRE_END_PIN='-')OR(TBL1.WIRE_END_PN ='M39029/22-22-22' AND TBL2.WIRE_END_PN ='M39029/22-191')OR(TBL2.WIRE_END_PN ='M39029/22-22-22' AND TBL1.WIRE_END_PN ='M39029/22-191') OR(TBL2.WIRE_END_PN ='M39029/5-115' AND TBL1.WIRE_END_PN ='M39029/5-20-20') OR(TBL1.WIRE_END_PN ='M39029/5-115' AND TBL2.WIRE_END_PN ='M39029/5-20-20') OR (TBL1.WIRE_END_PN ='M39029/22-22-22' AND TBL2.WIRE_END_PN ='M39029/22-191' AND TBL1.WIRE_END_REF NOT LIKE '%GD%' AND TBL2.WIRE_END_REF NOT LIKE '%GD%')OR(((TBL1.WIRE_END_PN ='M39029/22-20-20') OR (TBL1.WIRE_END_PN ='M39029/22-192')) AND TBL2.WIRE_END_PN ='M39029/101-553' AND TBL1.WIRE_END_REF NOT LIKE '%GD%' AND TBL2.WIRE_END_REF NOT LIKE '%GD%')OR(TBL2.WIRE_END_PN ='M39029/4-110' AND TBL1.WIRE_END_PN ='M39029/4-20-20')OR(TBL1.WIRE_END_PN ='M39029/4-110' AND TBL2.WIRE_END_PN ='M39029/4-20-20')OR(TBL2.WIRE_END_PN ='M39029/74-12C' AND TBL1.WIRE_END_PN ='M39029/74-400')OR(TBL2.WIRE_END_PN ='M39029/18-23-22' AND TBL1.WIRE_END_PN ='M39029/18-177')OR(TBL1.WIRE_END_PN ='M39029/18-23-22' AND TBL2.WIRE_END_PN ='M39029/18-177')OR(TBL2.WIRE_END_PN ='M39029/5-117' AND TBL1.WIRE_END_PN ='M39029/5-16-20')OR(TBL1.WIRE_END_PN ='M39029/5-117' AND TBL2.WIRE_END_PN ='M39029/5-16-20')OR(TBL1.WIRE_END_PN ='M39029/74-12C' AND TBL2.WIRE_END_PN ='M39029/74-400')OR(TBL2.WIRE_END_PN ='M39029/56-348' AND TBL1.WIRE_END_PN ='MS27490-22D')) AND ((TBL1.WIRE_LEN_MEAS = TBL1.WIRE_LEN_MEAS)OR(TBL1.WIRE_LEN_MEAS ='0001')OR(TBL2.WIRE_LEN_MEAS ='0001')OR(TBL1.WIRE_LEN_MEAS ='0002')OR(TBL2.WIRE_LEN_MEAS ='0002'))AND  TBL2.WIRE_END_REF ='",
        Module1.newModule.CountRefDes,
        "' AND TBL2.PART_NUMBER = '",
        Module1.newModule.newharn,
        "') ORDER BY TBL1.WIRE_END_PIN DESC,TBL1.WIRE_END_REF DESC,TBL1.WIRE_END_PN ,TBL1.WIRE_LEN_MEAS DESC "
      }));
      int num3 = (aset.Tables[0].Rows.Count - 1);
      int i = 0;
      while ((i <= num3)) {
        DataRow row = aset.Tables[0].Rows[i];
        string source = Conversions.ToString(row[7]);
        string str8 = Conversions.ToString(row[4]);
        string str7 = Conversions.ToString(Interaction.IIf((object.ReferenceEquals(row[8], DBNull.Value)), "-", RuntimeHelpers.GetObjectValue(row[8])));
        string str2 = "REMOVE";
        string str6 = Conversions.ToString(row[10]);
        string str4 = Conversions.ToString(Interaction.IIf((object.ReferenceEquals(row[9], DBNull.Value)), "-", RuntimeHelpers.GetObjectValue(row[9])));
        if (((str4.Contains("STRIP") & source.EndsWith("A")) && !str8.Contains("SH"))) {
          str4 = "16VE049012-1";
        }
        if (((str4.Contains("STRIP") & source.EndsWith("B")) && !str8.Contains("SH"))) {
          str4 = "16VE049012-1";
        }
        Module1.newModule.EndPoint = Conversions.ToString(row[6]);
        if ((((LikeOperator.LikeString(source, "*S77*", CompareMethod.Binary) | LikeOperator.LikeString(source, "*77#[A-Z]*", CompareMethod.Binary)) | LikeOperator.LikeString(source, "*73#[A-Z]", CompareMethod.Binary)) && !LikeOperator.LikeString(str8, "*SH*", CompareMethod.Binary))) {
            Module1.newModule.wireno1 = str8;
          DataSet set3 = new DataSet();
          set3 = data2.getData(string.Concat(new string[] {
            "SELECT SREFDES AS SREFDES,WREFDESID AS WREFDESID FROM TBLWIRESREMOVE WHERE WIRENO ='",
            Module1.newModule.wireno1,
            "' and WIRESPLID ='",
            Module1.newModule.PlanNumber,
            "'"
          }));
          if ((set3.Tables[0].Rows.Count != 0)) {
            Module1.newModule.refdesidnew = Conversions.ToInteger(set3.Tables[0].Rows[0]["WREFDESID"]);
            Module1.newModule.sRefDes = set3.Tables[0].Rows[0]["SREFDES"].ToString();
            Module1.newModule.REFDES1 = source;
          }
        }
        if ((((LikeOperator.LikeString(source, "*S77*", CompareMethod.Binary) | LikeOperator.LikeString(source, "*77#[A-Z]*", CompareMethod.Binary)) && LikeOperator.LikeString(str8, "*SH*", CompareMethod.Binary)) && (Module1.newModule.REFDES1 == source))) {
            if (Module1.newModule.BAckhrn)
            {
                Module1.newModule.BAckhrn = false;
          }
          data2.ExecuteSQL(string.Concat(new string[] {
            "UPDATE TBLWIRES SET PIN = '",
            source,
            "' ,SWIRENO ='",
            str8,
            "Z' , WREFDESID = ",
            Conversions.ToString(Module1.newModule.refdesidnew),
            " ,SREFDES ='",
            Module1.newModule.sRefDes,
            "' WHERE SREFDES ='",
            source,
            "' AND WIRENO='",
            Module1.newModule.wireno1,
            "' AND WIRESPLID = '",
            Module1.newModule.PlanNumber,
            "'"
          }));
          data2.ExecuteSQL(string.Concat(new string[] {
            "UPDATE TBLWIRESREMOVE SET PIN = '",
            source,
            "' ,SWIRENO ='",
            str8,
            "Z' , WREFDESID = ",
            Conversions.ToString(Module1.newModule.refdesidnew),
            " ,SREFDES ='",
            Module1.newModule.sRefDes,
            "' WHERE SREFDES ='",
            source,
            "' AND WIRENO='",
            Module1.newModule.wireno1,
            "' AND WIRESPLID = '",
            Module1.newModule.PlanNumber,
            "'"
          }));
          data2.ExecuteSQL(string.Concat(new string[] {
            "UPDATE TBLWIRES SET SWIRENO ='",
            str8,
            "ZZ' WHERE WIRENO='",
            Module1.newModule.wireno1,
            "' AND SREFDES ='",
            Module1.newModule.sRefDes,
            "' AND WIRESPLID = '",
            Module1.newModule.PlanNumber,
            "'"
          }));
          data2.ExecuteSQL(string.Concat(new string[] {
            "UPDATE TBLWIRESREMOVE SET SWIRENO ='",
            str8,
            "ZZ' WHERE WIRENO='",
            Module1.newModule.wireno1,
            "' AND SREFDES ='",
            Module1.newModule.sRefDes,
            "' AND WIRESPLID = '",
            Module1.newModule.PlanNumber,
            "'"
          }));
          str = "INSERT INTO tblWires ";
          str = (str + "(WIREACTid,WIRENO,wREFDESid,PIN,LENGTH,TERM,SWIRENO,SREFDES,SHIELD,WIRESPLID,ENDPOINT) VALUES ");
          str = string.Concat(new string[] {
            str,
            "('",
            str2,
            "','",
            str8,
            "',",
            Conversions.ToString(Module1.newModule.refdesidnew),
            ",'",
            source,
            "','",
            str6,
            "','",
            str4,
            "','",
            str8,
            "','",
            Module1.newModule.sRefDes,
            "','','",
            Module1.newModule.PlanNumber,
            "','",
            Module1.newModule.EndPoint,
            "')"
          });
          data2.ExecuteSQL(str);
          str = "INSERT INTO tblWiresREMOVE ";
          str = (str + "(WIREACTid,WIRENO,wREFDESid,PIN,LENGTH,TERM,SWIRENO,SREFDES,SHIELD,WIRESPLID,ENDPOINT) VALUES ");
          str = string.Concat(new string[] {
            str,
            "('",
            str2,
            "','",
            str8,
            "',",
            Conversions.ToString(Module1.newModule.refdesidnew),
            ",'",
            source,
            "','",
            str6,
            "','",
            str4,
            "','",
            str8,
            "','",
            Module1.newModule.sRefDes,
            "','','",
            Module1.newModule.PlanNumber,
            "','",
            Module1.newModule.EndPoint,
            "')"
          });
          data2.ExecuteSQL(str);
        } else {
          string str3;
          if (LikeOperator.LikeString(source, "*WT*", CompareMethod.Binary)) {
            str3 = "wire tie";
          } else {
            str3 = "connector";
          }
          str = string.Concat(new string[] {
            "SELECT REFDESID AS REFDESID FROM TBLREFDES WHERE REFDES = '",
            source,
            "' AND REFPLANID ='",
            Module1.newModule.PlanNumber,
            "'"
          });
          DataSet set2 = data2.getData(str);
          if ((set2.Tables[0].Rows.Count == 0)) {
            data2.ExecuteSQL(string.Concat(new string[] {
              "INSERT INTO TBLREFDES (REFDES,REPORTNOTE,OPN,HARNESS,REFPLANID,REFWT,REFPREVIEW) VALUES ('",
              source,
              "','',2,'",
              Module1.newModule.HARNESSID,
              "','",
              Module1.newModule.PlanNumber,
              "','Rework wires at ",
              str3,
              " ",
              source,
              " as follows and per 16PR145','')"
            }));
            str = string.Concat(new string[] {
              "SELECT REFDESID AS REFDESID FROM TBLREFDES WHERE REFDES = '",
              source,
              "' AND REFPLANID ='",
              Module1.newModule.PlanNumber,
              "'"
            });
            Module1.newModule.RefDesId = Conversions.ToInteger(data2.getData(str).Tables[0].Rows[0]["REFDESID"]);
          } else {
            Module1.newModule.RefDesId = Conversions.ToInteger(set2.Tables[0].Rows[0]["REFDESID"]);
          }
          str = "INSERT INTO tblWires ";
          str = (str + "(WIREACTid,WIRENO,wREFDESid,PIN,LENGTH,TERM,SWIRENO,SREFDES,SHIELD,WIRESPLID,ENDPOINT) VALUES ");
          str = string.Concat(new string[] {
            str,
            "('",
            str2,
            "','",
            str8,
            "',",
            Conversions.ToString(Module1.newModule.RefDesId),
            ",'",
            str7,
            "','",
            str6,
            "','",
            str4,
            "','",
            str8,
            "','",
            source,
            "','','",
            Module1.newModule.PlanNumber,
            "','",
            Module1.newModule.EndPoint,
            "')"
          });
          data2.ExecuteSQL(str);
          str = "INSERT INTO tblWiresREMOVE ";
          str = (str + "(WIREACTid,WIRENO,wREFDESid,PIN,LENGTH,TERM,SWIRENO,SREFDES,SHIELD,WIRESPLID,ENDPOINT) VALUES ");
          str = string.Concat(new string[] {
            str,
            "('",
            str2,
            "','",
            str8,
            "',",
            Conversions.ToString(Module1.newModule.RefDesId),
            ",'",
            str7,
            "','",
            str6,
            "','",
            str4,
            "','",
            str8,
            "','",
            source,
            "','','",
            Module1.newModule.PlanNumber,
            "','",
            Module1.newModule.EndPoint,
            "')"
          });
          data2.ExecuteSQL(str);
        }
        row = null;
        i += 1;
      }
      Application.DoEvents();
      Cursor.Current = Cursors.WaitCursor;
      aset = data2.getData(string.Concat(new string[] {
        " SELECT * FROM PTP TBL1 WHERE  PART_NUMBER = '",
        Module1.newModule.newharn,
        "' AND  TBL1.WIRE_END_REF ='",
        Module1.newModule.CountRefDes,
        "' AND  WIRE_NUMBER NOT IN( SELECT WIRE_NUMBER FROM PTP TBL2 WHERE  ((TBL1.WIRE_END_PIN = TBL2.WIRE_END_PIN)OR(TBL1.WIRE_END_PIN IS NULL AND TBL2.WIRE_END_PIN = '-' ))  AND TBL1.WIRE_END_REF = TBL2.WIRE_END_REF AND ((TBL1.WIRE_END_PN = TBL2.WIRE_END_PN)OR (TBL1.WIRE_END_PN IS NULL AND TBL2.WIRE_END_PIN='-')OR(TBL1.WIRE_END_PN ='M39029/22-22-22' AND TBL2.WIRE_END_PN ='M39029/22-191')OR(TBL2.WIRE_END_PN ='M39029/22-22-22' AND TBL1.WIRE_END_PN ='M39029/22-191') OR(TBL2.WIRE_END_PN ='M39029/5-115' AND TBL1.WIRE_END_PN ='M39029/5-20-20') OR(TBL1.WIRE_END_PN ='M39029/5-115' AND TBL2.WIRE_END_PN ='M39029/5-20-20') OR (TBL1.WIRE_END_PN ='M39029/22-22-22' AND TBL2.WIRE_END_PN ='M39029/22-191' AND TBL1.WIRE_END_REF NOT LIKE '%GD%' AND TBL2.WIRE_END_REF NOT LIKE '%GD%')OR(((TBL1.WIRE_END_PN ='M39029/22-20-20') OR (TBL1.WIRE_END_PN ='M39029/22-192')) AND TBL2.WIRE_END_PN ='M39029/101-553' AND TBL1.WIRE_END_REF NOT LIKE '%GD%' AND TBL2.WIRE_END_REF NOT LIKE '%GD%')OR(TBL2.WIRE_END_PN ='M39029/4-110' AND TBL1.WIRE_END_PN ='M39029/4-20-20')OR(TBL1.WIRE_END_PN ='M39029/4-110' AND TBL2.WIRE_END_PN ='M39029/4-20-20')OR(TBL2.WIRE_END_PN ='M39029/74-12C' AND TBL1.WIRE_END_PN ='M39029/74-400')OR(TBL2.WIRE_END_PN ='M39029/18-23-22' AND TBL1.WIRE_END_PN ='M39029/18-177')OR(TBL1.WIRE_END_PN ='M39029/18-23-22' AND TBL2.WIRE_END_PN ='M39029/18-177')OR(TBL2.WIRE_END_PN ='M39029/5-117' AND TBL1.WIRE_END_PN ='M39029/5-16-20')OR(TBL1.WIRE_END_PN ='M39029/5-117' AND TBL2.WIRE_END_PN ='M39029/5-16-20')OR(TBL1.WIRE_END_PN ='M39029/74-12C' AND TBL2.WIRE_END_PN ='M39029/74-400')OR(TBL2.WIRE_END_PN ='M39029/56-348' AND TBL1.WIRE_END_PN ='MS27490-22D')) AND ((TBL1.WIRE_LEN_MEAS = TBL1.WIRE_LEN_MEAS)OR(TBL1.WIRE_LEN_MEAS ='0001')OR(TBL2.WIRE_LEN_MEAS ='0001')OR(TBL1.WIRE_LEN_MEAS ='0002')OR(TBL2.WIRE_LEN_MEAS ='0002'))AND  TBL2.WIRE_END_REF ='",
        Module1.newModule.CountRefDes,
        "' AND TBL2.PART_NUMBER = '",
        Module1.newModule.oldharn,
        "') ORDER BY TBL1.WIRE_END_PIN DESC,TBL1.WIRE_END_REF DESC,TBL1.WIRE_END_PN ,TBL1.WIRE_LEN_MEAS DESC "
      }));
      int num4 = (aset.Tables[0].Rows.Count - 1);
      int j = 0;
      while ((j <= num4)) {
        DataRow row2 = aset.Tables[0].Rows[j];
        string str11 = Conversions.ToString(row2[7]);
        string str13 = Conversions.ToString(Interaction.IIf((object.ReferenceEquals(row2[8], DBNull.Value)), "-", RuntimeHelpers.GetObjectValue(row2[8])));
        string str9 = "ADD";
        string str14 = Conversions.ToString(row2[4]);
        string str12 = Conversions.ToString(row2[10]);
        string str10 = Conversions.ToString(Interaction.IIf((object.ReferenceEquals(row2[9], DBNull.Value)), "-", RuntimeHelpers.GetObjectValue(row2[9])));
        Module1.newModule.EndPoint = Conversions.ToString(row2[6]);
        if (((str10.Contains("STRIP") & str11.EndsWith("A")) && !str14.Contains("SH"))) {
          str10 = "16VE049012-1";
        }
        if (((str10.Contains("STRIP") & str11.EndsWith("B")) && !str14.Contains("SH"))) {
          str10 = "16VE049012-1";
        }
        if (((LikeOperator.LikeString(str11, "*S77*", CompareMethod.Binary) | LikeOperator.LikeString(str11, "*77#[A-Z]*", CompareMethod.Binary)) && !LikeOperator.LikeString(str14, "*SH*", CompareMethod.Binary))) {
            Module1.newModule.wireno1 = str14;
          DataSet set5 = new DataSet();
          set5 = data2.getData(string.Concat(new string[] {
            "SELECT SREFDES AS SREFDES,WREFDESID AS WREFDESID FROM TBLWIRESADD WHERE WIRENO ='",
            Module1.newModule.wireno1,
            "' AND WIRESPLID ='",
            Module1.newModule.PlanNumber,
            "'"
          }));
          if ((set5.Tables[0].Rows.Count != 0)) {
            Module1.newModule.refdesidnew = Conversions.ToInteger(set5.Tables[0].Rows[0]["WREFDESID"]);
            Module1.newModule.sRefDes = set5.Tables[0].Rows[0]["SREFDES"].ToString();
            Module1.newModule.REFDES1 = str11;
          }
        }
        if ((((LikeOperator.LikeString(str11, "*S77*", CompareMethod.Binary) | LikeOperator.LikeString(str11, "*77#[A-Z]*", CompareMethod.Binary)) && LikeOperator.LikeString(str14, "*SH*", CompareMethod.Binary)) && (Module1.newModule.REFDES1 == str11))) {
          if (Module1.newModule.BAckhrn) {
            Module1.newModule.BAckhrn = false;
          }
          data2.ExecuteSQL(string.Concat(new string[] {
            "UPDATE TBLWIRES SET PIN = '",
            str11,
            "' ,SWIRENO ='",
            str14,
            "Z' , WREFDESID = ",
            Conversions.ToString(Module1.newModule.refdesidnew),
            " ,SREFDES ='",
            Module1.newModule.sRefDes,
            "' WHERE SREFDES ='",
            str11,
            "' AND WIRENO='",
            Module1.newModule.wireno1,
            "' AND WIRESPLID = '",
            Module1.newModule.PlanNumber,
            "'"
          }));
          data2.ExecuteSQL(string.Concat(new string[] {
            "UPDATE TBLWIRESADD SET PIN = '",
            str11,
            "' ,SWIRENO ='",
            str14,
            "Z' , WREFDESID = ",
            Conversions.ToString(Module1.newModule.refdesidnew),
            " ,SREFDES ='",
            Module1.newModule.sRefDes,
            "' WHERE SREFDES ='",
            str11,
            "' AND WIRENO='",
            Module1.newModule.wireno1,
            "' AND WIRESPLID = '",
            Module1.newModule.PlanNumber,
            "'"
          }));
          data2.ExecuteSQL(string.Concat(new string[] {
            "UPDATE TBLWIRES SET SWIRENO ='",
            str14,
            "ZZ' WHERE SWIRENO='",
            Module1.newModule.wireno1,
            "' AND SREFDES ='",
            Module1.newModule.sRefDes,
            "' AND WIRESPLID = '",
            Module1.newModule.PlanNumber,
            "'"
          }));
          data2.ExecuteSQL(string.Concat(new string[] {
            "UPDATE TBLWIRESADD SET SWIRENO ='",
            str14,
            "ZZ' WHERE SWIRENO='",
            Module1.newModule.wireno1,
            "' AND SREFDES ='",
            Module1.newModule.sRefDes,
            "' AND WIRESPLID = '",
            Module1.newModule.PlanNumber,
            "'"
          }));
          str = "INSERT INTO tblWires ";
          str = (str + "(WIREACTid,WIRENO,wREFDESid,PIN,LENGTH,TERM,SWIRENO,SREFDES,SHIELD,WIRESPLID) VALUES ");
          str = string.Concat(new string[] {
            str,
            "('",
            str9,
            "','",
            str14,
            "',",
            Conversions.ToString(Module1.newModule.refdesidnew),
            ",'",
            str11,
            "','",
            str12,
            "','",
            str10,
            "','",
            str14,
            "','",
            Module1.newModule.sRefDes,
            "','','",
            Module1.newModule.PlanNumber,
            "')"
          });
          data2.ExecuteSQL(str);
          str = "INSERT INTO tblWiresADD ";
          str = (str + "(WIREACTid,WIRENO,wREFDESid,PIN,LENGTH,TERM,SWIRENO,SREFDES,SHIELD,WIRESPLID) VALUES ");
          str = string.Concat(new string[] {
            str,
            "('",
            str9,
            "','",
            str14,
            "',",
            Conversions.ToString(Module1.newModule.refdesidnew),
            ",'",
            str11,
            "','",
            str12,
            "','",
            str10,
            "','",
            str14,
            "','",
            Module1.newModule.sRefDes,
            "','','",
            Module1.newModule.PlanNumber,
            "')"
          });
          data2.ExecuteSQL(str);
        } else {
          string str15;
          if (LikeOperator.LikeString(str11, "*WT*", CompareMethod.Binary)) {
            str15 = "wire tie";
          } else {
            str15 = "connector";
          }
          str = string.Concat(new string[] {
            "SELECT REFDESID AS REFDESID FROM TBLREFDES WHERE REFDES = '",
            str11,
            "' AND REFPLANID ='",
            Module1.newModule.PlanNumber,
            "'"
          });
          DataSet set4 = data2.getData(str);
          if ((set4.Tables[0].Rows.Count == 0)) {
            data2.ExecuteSQL(string.Concat(new string[] {
              "INSERT INTO TBLREFDES (REFDES,REPORTNOTE,OPN,HARNESS,REFPLANID,REFWT,REFPREVIEW) VALUES ('",
              str11,
              "','',2,'",
              Module1.newModule.HARNESSID,
              "','",
              Module1.newModule.PlanNumber,
              "','Rework wires at ",
              str15,
              " ",
              str11,
              " as follows and per 16PR145','')"
            }));
            str = string.Concat(new string[] {
              "SELECT REFDESID AS REFDESID FROM TBLREFDES WHERE REFDES = '",
              str11,
              "' AND REFPLANID ='",
              Module1.newModule.PlanNumber,
              "'"
            });
            Module1.newModule.RefDesId = Conversions.ToInteger(data2.getData(str).Tables[0].Rows[0]["REFDESID"]);
          } else {
              Module1.newModule.RefDesId = Conversions.ToInteger(set4.Tables[0].Rows[0]["REFDESID"]);
          }
          str = "INSERT INTO tblWires ";
          str = (str + "(WIREACTid,WIRENO,wREFDESid,PIN,LENGTH,TERM,SWIRENO,SREFDES,SHIELD,WIRESPLID,ENDPOINT) VALUES ");
          str = string.Concat(new string[] {
            str,
            "('",
            str9,
            "','",
            str14,
            "',",
            Conversions.ToString(Module1.newModule.RefDesId),
            ",'",
            str13,
            "','",
            str12,
            "','",
            str10,
            "','",
            str14,
            "','",
            str11,
            "','','",
            Module1.newModule.PlanNumber,
            "','",
            Module1.newModule.EndPoint,
            "')"
          });
          data2.ExecuteSQL(str);
          str = "INSERT INTO tblWiresADD ";
          str = (str + "(WIREACTid,WIRENO,wREFDESid,PIN,LENGTH,TERM,SWIRENO,SREFDES,SHIELD,WIRESPLID,ENDPOINT) VALUES ");
          str = string.Concat(new string[] {
            str,
            "('",
            str9,
            "','",
            str14,
            "',",
            Conversions.ToString(Module1.newModule.RefDesId),
            ",'",
            str13,
            "','",
            str12,
            "','",
            str10,
            "','",
            str14,
            "','",
            str11,
            "','','",
            Module1.newModule.PlanNumber,
            "','",
            Module1.newModule.EndPoint,
            "')"
          });
          data2.ExecuteSQL(str);
        }
        row2 = null;
        j += 1;
      }
      if (Module1.newModule.refdecount.Contains("NEAR"))//JMR added Module1.newModule onto refdecount and also on the one a few lines below
      {
        str = string.Concat(new string[] {
          "SELECT REFDESID AS REFDESID FROM TBLREFDES WHERE REFDES = '",
          Module1.newModule.refdecount,
          "' AND REFPLANID ='",
          Module1.newModule.PlanNumber,
          "'"
        });
        DataSet set4 = data2.getData(str);
        if ((set4.Tables[0].Rows.Count == 0)) {

        } else {
            Module1.newModule.RefDesId = Conversions.ToInteger(set4.Tables[0].Rows[0]["REFDESID"]);
        }
        data.ExecuteSQL(string.Concat(new string[] {
          "DELETE * FROM TBLREFDES WHERE REFDES ='" + Module1.newModule.refdecount + "' AND RefPlanId ='",
          Module1.newModule.PlanNumber,
          "'"
        }));
      }

      DevExpress.XtraEditors.XtraMessageBox.Show("Restore completed.", "Set connector to default state", MessageBoxButtons.OK);
      frmElectrical.newfrmElectrical1.REFRESHDATA();
      this.Close();

    }

    private void  // ERROR: Handles clauses are not supported in C#
GridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
    {
        try
        {
            if (Module1.newModule.CountRefDes.Contains("("))
            {
                int index = Module1.newModule.CountRefDes.IndexOf("(");
                Module1.newModule.REFDES1 = Module1.newModule.CountRefDes.Substring((index + 5));
                Module1.newModule.REFDES1 = Module1.newModule.REFDES1.Substring(0, (Module1.newModule.REFDES1.Length - 1));
                Module1.newModule.CountRefDes = Module1.newModule.CountRefDes.Substring(0, index).Trim();
            }
            else
            {
                Module1.newModule.REFDES1 = Module1.newModule.CountRefDes;
            }

            if (Operators.ConditionalCompareObjectEqual(this.GridView1.GetRowCellValue(e.RowHandle, "STEP"), "1", false) && Operators.ConditionalCompareObjectNotEqual(this.GridView1.GetRowCellValue(e.RowHandle, "QTY"), 0, false))
            {
                e.Appearance.BackColor = Color.LightPink;
            }           
        }
        catch (Exception ex)
        {
            ProjectData.SetProjectError(ex);
            Exception exception = ex;
            ProjectData.ClearProjectError();
        }
    }

    private void  // ERROR: Handles clauses are not supported in C#
SimpleButton2_Click(System.Object sender, System.EventArgs e)
    {

      clsData data = new clsData();
      DataSet aset = new DataSet();
      string str = "";
      string str7 = "";
      string str4 = "";
      string str10 = "";
      aset = data.getData(string.Concat(new string[] {
        "SELECT * FROM PTP WHERE PART_NUMBER ='",
        Module1.newModule.newharn,
        "'  AND WIRE_END_REF ='",
        Module1.newModule.CountRefDes,
        "' AND WIRE_END_PIN LIKE 'L[0-9]%' AND WIRE_NUMBER NOT IN(SELECT WIRENO AS WIRE_NUMBER FROM TBLWIRES WHERE WIRESPLID ='",
        Module1.newModule.plnumber,
        "') ORDER BY WIRE_END_PIN"
      }));
      if ((aset.Tables[0].Rows.Count != 0)) {
        string str13;
        int num5 = (aset.Tables[0].Rows.Count - 1);
        int i = 0;
        while ((i <= num5)) {
          str = Conversions.ToString(aset.Tables[0].Rows[i]["WIRE_NUMBER"]);
          if ((i != 0)) {
            str = str.Substring(str.IndexOf("-"), 4);
          }
          //if ((((str7 == str10) && (str7 != "")) ? 1 : 0 == 0)) 
          if (str7 != str10 || str7 == "")//JMR -- changed the above line to this line
          {
            str7 = Conversions.ToString(aset.Tables[0].Rows[i]["WIRE_END_PIN"]);
          }
          if ((i != 0)) {
            str4 = (str4 + " , ");
          }
          str4 = (str4 + str);
          str10 = str7;
          i += 1;
        }
        str10 = Conversions.ToString(aset.Tables[0].Rows[0]["WIRE_END_PIN"]);
        aset = data.getData(string.Concat(new string[] {
          "SELECT * FROM PTP WHERE PART_NUMBER ='",
          Module1.newModule.oldharn,
          "'  AND WIRE_END_PIN ='",
          str10,
          "'"
        }));
        string str2 = "";
        string str8 = "";
        string str5 = "";
        string str11 = "";
        int num6 = (aset.Tables[0].Rows.Count - 1);
        int j = 0;
        while ((j <= num6)) {
          str2 = Conversions.ToString(aset.Tables[0].Rows[j]["WIRE_NUMBER"]);
          if ((j != 0)) {
            str2 = str2.Substring(str2.IndexOf("-"), 4);
          }
          if ((j != 0)) {
            str5 = (str5 + " , ");
          }
          str5 = (str5 + str2);
          if ((j != 0)) {
            str5 = str5;
          }
          str11 = str8;
          j += 1;
        }
        string str12 = "";
        aset = data.getData(string.Concat(new string[] {
          "SELECT * FROM PTP WHERE PART_NUMBER ='",
          Module1.newModule.newharn,
          "'  AND WIRE_END_REF ='",
          Module1.newModule.CountRefDes,
          "' AND WIRE_END_PIN LIKE 'L[0-9]%' AND WIRE_NUMBER IN(SELECT WIRENO AS WIRE_NUMBER FROM TBLWIRES WHERE SREFDES ='",
          Module1.newModule.CountRefDes,
          "' AND WIRESPLID ='",
          Module1.newModule.plnumber,
          "') ORDER BY WIRE_END_PIN"
        }));
        str12 = Conversions.ToString(aset.Tables[0].Rows[0]["WIRE_END_PIN"]);
        string str3 = "";
        string str9 = "";
        string str6 = "";
        if ((aset.Tables[0].Rows.Count != 0)) {
          int num7 = (aset.Tables[0].Rows.Count - 1);
          int k = 0;
          while ((k <= num7)) {
            str3 = Conversions.ToString(aset.Tables[0].Rows[k]["WIRE_NUMBER"]);
            if ((k != 0)) {
              str3 = str3.Substring(str3.IndexOf("-"), 4);
            }
            if ((k != 0)) {
              str6 = (str6 + " , ");
            }
            str6 = (str6 + str3);
            if ((k != 0)) {
              str6 = str6;
            }
            str12 = str9;
            k += 1;
          }
        }
        DataSet set2 = new DataSet();
        set2 = data.getData(string.Concat(new string[] {
          "SELECT * FROM PTP WHERE PART_NUMBER ='",
          Module1.newModule.newharn,
          "'  AND WIRE_END_REF ='",
          Module1.newModule.CountRefDes,
          "' AND WIRE_END_PN <>'STRIP' AND WIRE_END_PIN ='",
          str7,
          "'"
        }));
        if ((set2.Tables[0].Rows.Count == 0)) {
          str13 = "_________";
        } else {
          str13 = Conversions.ToString(set2.Tables[0].Rows[0]["WIRE_END_PN"]);
        }
        if ((str6 == "")) {
            Module1.newModule.PartsStep = string.Concat(new string[] {
            "REMOVE WIRES ",
            str5,
            " AS CLOSE TO TERMINAL ",
            str10,
            " AS POSSIBLE. KEEP WIRE(S) ",
            str4,
            " AND PUT THEM TO NEW TERMINAL ",
            str7,
            "  PARTNUMBER ",
            str13,
            "."
          });
        } else {
            Module1.newModule.PartsStep = string.Concat(new string[] {
            "REMOVE WIRES ",
            str5,
            " AS CLOSE TO TERMINAL ",
            str10,
            " AS POSSIBLE. KEEP WIRE(S) ",
            str4,
            " AND ADD WIRES ",
            str6,
            ".  PUT ALL WIRES TO NEW TERMINAL ",
            str7,
            "  PARTNUMBER ",
            str13,
            "."
          });
        }
        this.Close();
      }
    }



    private void gridStepWires_Click(object sender, EventArgs e)
    {

    }

    public frmStepWires()
    {
        InitializeComponent(); 
    }
  }
}

